#include <iostream>
#include <windows.h>

#include "dllTest60.h"
#include "uThread.h"
#include "uCritSec.h"

int iVar,iProc,iJet;
unsigned char BoolIn1, BoolIn2;
BOOL bRet;
MSG msg;

void DllTest60(unsigned char, unsigned char);

sCriticalSection cs;
sThread t1(TRUE);

void Exec_t1()
{
	std::cout<<"\nThread-1:In CRITICAL SECTION";

//	DllTest60(&BoolIn1, &BoolIn2);

	while (iProc==1)
	{
		cs.Lock();
		if (iVar==10)
		{
			if (iJet==0)
			{
				std::cout<<"\n\t1_"<<iVar;
				Sleep(50);
				iJet=1;
			}
		}
		else if (iVar==96)
		{
			if (iJet==0)
			{
				std::cout<<"\t1_"<<iVar;
				Sleep(50);
				iJet=1;
			}
		}
		cs.Unlock();
	}
	std::cout<<"\nThread-1:Out of CRITICAL SECTION";
}

void main()
{
	BoolIn1=TRUE;
	BoolIn2=TRUE;
	iProc=1;

	void sub();

	std::cout<<"\nMain started.";

//	Start the message loop. 
//	while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
//	{ 
//		if (bRet == -1)
//		{
//			handle the error and possibly exit
//		}
//		else
//		{
//			TranslateMessage(&msg); 
//			DispatchMessage(&msg); 
//		}
//	} 

	//A function from a Dll made with LV
	DllTest60(&BoolIn1, &BoolIn2);	//This function makes a beep sound.

	sub();

	for (int j=0; j<100; j++)
	{
		iJet=0;
		iVar=j*2;
		Sleep(100);
	}

	iProc=0;
	std::cout<<"\n.......................";
	Sleep(100);
	std::cout<<"\nProgram about to die...";
	std::cin.get();
}

void sub()
{
	t1.OnExecute = Exec_t1;
	t1.Resume();
}